<template>
  <div class="dialog">
    <el-dialog :title="nowChanceStau === 'pass' ? '通过确认' : '不通过原因'" :visible.sync="showDialog" width="25%" top="0"
      :close-on-click-modal="false" @close="cancel">
      <el-form ref="ruleForm" label-position="left" :model="formData" :rules="rules" class="el-form">
        <el-form-item v-if="nowChanceStau === 'unpass'" label="不通过原因: " prop="failReason" class="w100p">
          <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model="formData.failReason">
          </el-input>
        </el-form-item>
        <el-form-item v-else class="w100p">
          <div class="font-cls"><span>确定通过审核吗?</span></div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancelbtn" @click="cancel()">取 消</el-button>
        <el-button type="primary" class="savebtn" @click="save('ruleForm')">保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import HealthTaskHandlingApi from "@/api/health-management/health-task-handling";
export default {
  name: '',
  components: {},
  props: {
    nowChanceStau: {
      type: String,
      default: ""
    },
    show: {
      type: Boolean,
      default: false
    },
    editObject: {
      type: [Object],
      default: () => {
        return {}
      }
    },
  },
  data () {
    return {
      formData: {
        failReason: null
      },
      rules: {
        failReason: [
          { required: true, message: "请输入未通过原因", trigger: 'blur' }
        ],
      },
      showDialog: this.show
    };
  },

  watch: {
    show (v) {
      this.showDialog = v;
      this.formData = this.editObject
    },
    nowChanceStau (v) {
      if (v === 'pass') {
      }
      if (v === 'unpass') {
      }
    }
  },
  created () {
  },
  mounted () {
  },
  methods: {
    save (formData) {
      if (this.nowChanceStau === "pass") {
        let params = {
          auditedId: this.editObject.diseaseDealId,
          auditStaffId: sessionStorage.getItem('staffId'),
          auditStaffName: sessionStorage.getItem('staffName'),
          auditType: 'PASS',
        }
        HealthTaskHandlingApi.audit(params).then(res => {
          if (res.success) {
            this.$message.success("操作通过");
            this.close()
          } else {
            this.$message.info(res.message ? res.message : "系统错误,请稍后再试");
          }
        });
      }
      if (this.nowChanceStau === "unpass") {
        if (this.formData.failReason) {
          let params = {
            auditedId: this.editObject.diseaseDealId,
            auditStaffId: sessionStorage.getItem('staffId'),
            auditStaffName: sessionStorage.getItem('staffName'),
            auditType: 'NOT_PASS',
            failReason: this.formData.failReason
          }
          HealthTaskHandlingApi.audit(params).then(res => {
            if (res.success) {
              this.$message.success("操作成功");
              this.close()
            } else {
              this.$message.info(res.message ? res.message : "系统错误,请稍后再试");
            }
          });
        } else {
          this.$message('请输入不通过原因')
        }
      }
    },
    close () {
      this.$emit("closeDialog");
      this.$refs['ruleForm'].resetFields()
    },
    cancel () {
      this.$emit("cancelDialog");
      this.$refs['ruleForm'].resetFields()
    }
  }
};
</script>

<style lang="scss" scoped>
.font-cls {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  font-size: 20px;
}
</style>
